Skip to content

fix(network): fail when open mode cannot enforce block_metadata_endpoint - #1201

Draft
coipond-coder[bot] wants to merge 5 commits into
masterfrom
fix/54627-open-metadata-fail-closed
Draft

coipond-coder[bot] wants to merge 5 commits into
masterfrom
fix/54627-open-metadata-fail-closed

Conversation

@coipond-coder

@coipond-coder coipond-coder Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Redmine: 54627

Summary

With block_metadata_endpoint = true (the default), open mode used to warn and start the container when it could not install the 169.254.0.0/16 reject. Now it refuses to start, with the reason and the fix:

  • coi shell / coi container start (Manager.SetupForContainer): returns an error when nft is not usable (use_sudo = false, nft not installed, no passwordless sudo for it), when there is no container IP, or when the nft rules fail. The iptables fallback runs only with the block off. The boot block stays. coi shell stops the container, because open mode's boot block is best effort and may not be in place; it removes the boot block only when nft is usable. coi container start already stops it (stopUnisolated).
  • coi run (ApplyOpenMetadataBlock): returns the same error instead of warnings. The run pipeline deletes the container.
  • Error text: the reason, then the fix: install nftables, coi health --fix, do not set use_sudo = false, or set block_metadata_endpoint = false in trusted config. errNftNotAvailable's "use open mode" hint now adds block_metadata_endpoint = false.
  • Removed Manager.MetadataUnenforced and the grants check that used it: a successful open-mode setup now always has the reject when the setting is on.
  • coi health: the nft check passes open mode only when block_metadata_endpoint = false. Otherwise it checks nft as for restricted mode (use_sudo=false: warning that points at the setting). The Colima hints add block_metadata_endpoint = false, and so do the install.sh nft prompts and the coi health --fix nft summary.
  • Schema descriptions (block_metadata_endpoint, use_sudo) and the starter config are updated.

Setups this stops (default block_metadata_endpoint = true)

  • open mode with use_sudo = false
  • open mode on a host without nftables, or without passwordless sudo for nft (e.g. Colima/Lima without the sudoers rule)
  • open mode where nft needs the iptables fallback (nft not usable)
  • open mode where the nft rules fail to apply, or no container IP is found

Fix for each: make nft usable (sudo apt install nftables, coi health --fix, keep use_sudo on), or set block_metadata_endpoint = false in ~/.coi/config.toml.

Tests

  • TestSetupForContainer_OpenMetadataNoNft, TestSetupForContainer_OpenMetadataRulesFail (network): the error, its reason, and the boot block kept.
  • TestPhaseSetupNetwork_OpenMetadataNotEnforced (session, coi shell): no usable nft, nft not installed and failed nft rules stop the container, with no boot-block warning when nft is missing. A restricted failure does not stop it.
  • TestContainerStartLaunch_OpenMetadataNotEnforcedStops (cli): coi container start and launch stop the container.
  • TestApplyNetworkIsolation_OpenMetadataBlock (cli, coi run): no usable nft and failed nft rules return the error and no teardown.
  • TestApplyOpenMetadataBlock_NoNft, TestCheckNft_UseSudoFalse (health case added).
  • Each test fails with its branch disabled (mutants checked locally).
  • E2e: tests/run/run_open_metadata_block_needs_nft.py (open + use_sudo = false, default block): coi run fails, the command does not run, the error names the reason and the fix, and the container is deleted. tests/network/test_no_sudo_mode.py: the open-mode tests set block_metadata_endpoint = false. A new health case checks the warning.
  • Not run locally (they need Incus): the e2e tests. The health cases of test_no_sudo_mode.py were run locally against the built binary: pass.

Local: gofmt, go vet, golangci-lint (0 issues), go test -short -race ./..., ruff, check-ci-coverage.py: pass.

Performance impact

none. Only the failure paths change. A successful open-mode setup makes the same nft and Incus calls as before.

With block_metadata_endpoint on, open mode warned and started the container
when the metadata reject could not be installed (no usable nft, no container
IP, nft failed). coi shell, coi run and coi container start now fail with the
reason and the fix, and stop the container.
@coipond-coder coipond-coder Bot added bug Something isn't working security Security fixes and hardening labels Dec 5, 2026
…he open-mode stops

Install and health --fix texts say open mode without nft needs
block_metadata_endpoint = false. coi shell skips the boot-block removal
without usable nft. Tests: container start/launch stop, the open-mode health
message.
… shell setup

stopOpenUnisolated checks NftUsable with the network config, so use_sudo =
false skips the removal too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working security Security fixes and hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants